<?php
require_once ( PATH_DATABASE.'class.dbcontrol.inc.php' );
class Db_Transactions extends db {
	public function __construct(){
//		$this->setTable('ams_packet');
	}
	public function doListTransactions(){
		$sSql = "SELECT B.*, P.name FROM 
					(SELECT T.*, A.admin_fullname FROM ams_transactions as T
					INNER JOIN ams_admin as A
					ON T.user_id = A.admin_id WHERE A.admin_role='3') as B
					INNER JOIN ams_packet as P
					ON B.packet_id = P.id
					";
		return parent::execute_query($sSql, __LINE__, __FILE__);
	}
	public function doDeleteTransactionsById($id){
		$sSql = "DELETE FROM `ams_transactions` WHERE `id` = '$id'"; 			 
		parent::execute_query($sSql, __LINE__, __FILE__);
		return true;
	}
	public function doUpdateTransactionsById($datetime,$status, $id){
		parent::StartTrans();     
        parent::update( 'ams_transactions', Array(
        						'status' =>$status,		
        						'activity' =>$datetime,					 
              ),Array('trans_id' => $id),__LINE__,__FILE__);
		parent::Commit();
		return true;
	}
	public function doGetTransactionsById($id){
		$sSql = "SELECT * FROM ams_transactions WHERE trans_id='$id'";
		return parent::execute_query($sSql, __LINE__, __FILE__);
	}
	public function doInsertUserAccount($aData){
	 	parent::StartTrans();
        parent::insert( 'ams_user_account', Array(
        						'user_id' => $aData['user_id'],
        						'can_be_downloaded_items' => $aData['can_be_downloaded_items'],
        						'downloaded_items' => $aData['downloaded_items'],
        						'start_date' => $aData['start_date'],
        						'end_date' => $aData['end_date'],
              ), false,__LINE__, __FILE__ );
        $id = parent::get_last_insert_id();           
        parent::Commit();
        return $id;
	}
	public function doUpdateUserAccountById($aData, $user_id){
		parent::StartTrans();     
        parent::update( 'ams_user_account', Array(
        						'can_be_downloaded_items' => $aData['can_be_downloaded_items'],
        						'downloaded_items' => $aData['downloaded_items'],
        						'start_date' => $aData['start_date'],
        						'end_date' => $aData['end_date'],				 
              ),Array('user_id' => $user_id),__LINE__,__FILE__);
		parent::Commit();
		return true;
	}
	public function docheckExistUserId($user_id){
		$sSql = "SELECT * FROM ams_user_account WHERE user_id='$user_id'";
		return parent::execute_query($sSql, __LINE__, __FILE__);
	}
	/*public function doGetUserAccountById($user_id){
		$sSql = "SELECT * FROM ams_user_account WHERE user_id='$user_id'";
		return parent::execute_query($sSql, __LINE__, __FILE__);
	}*/
}